package org.javascud.extensions.cxf.zookeeper;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.javascud.extensions.cxf.AbstractLoadBalanceStrategy;
import org.javascud.extensions.zookeeper.ZooKeeperChildrenWatcher;

import java.util.List;

/**
 * watcher service from zookeeper.
 *
 * @author Felix Zhang   Date:2010-10-16 01:13
 */
public class ServiceEndpointsWatcher extends ZooKeeperChildrenWatcher {
    private static Log logger = LogFactory.getLog(ServiceEndpointsWatcher.class);

    private AbstractLoadBalanceStrategy strategy;

    public void setStrategy(AbstractLoadBalanceStrategy strategy) {
        this.strategy = strategy;
    }

    @Override
    protected void updateData(List<String> members) {
        strategy.setAlternateAddresses(members);
        logger.info("get memebers: " + members.size());
    }
}
